def crc16(strbuf, length):
    crc = 0xffff

    for i in range(length):
        crc = crc ^ (strbuf[i] & 0xffff)
        crc = crc & 0xffff

        for j in range(8):
            if crc & 0x01:
                crc = crc >> 1
                crc = crc & 0xffff
                crc = crc ^ 0xa001
            else:
                crc = crc >> 1
                crc = crc & 0xffff

    return crc


# buf = [0x7C, 0x80, 0x00, 0x24, 0x07, 0x29, 0x00, 0x00, 0x00, 0x00, 0x30,
#        0x30, 0x11, 0x22, 0x33, 0x44, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
#        0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30]
# result = crc16(buf, len(buf))
# resultL = result & 0xff
# resultH = (result >> 8) & 0xff
# print('0x%2x, 0x%2x' % (resultL, resultH))
